﻿package model.entity.product;

import java.util.Map;
import java.util.Map.Entry;

import javax.persistence.MappedSuperclass;


@MappedSuperclass
public class Toy extends Product {

	protected int ageRestriction;
	protected String size;
	protected String material;
	
	public int getAgeRestriction() {
		return ageRestriction;
	}

	public void setAgeRestriction(int ageRestriction) {
		this.ageRestriction = ageRestriction;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getMaterial() {
		return material;
	}

	public void setMaterial(String material) {
		this.material = material;
	}

	public static Map<String, Class<?>> fieldMap(){
		Map<String, Class<?>> fieldMap = Electronic.fieldMap();
		fieldMap.put("ageRestriction", int.class);
		fieldMap.put("size", String.class);
		fieldMap.put("material", String.class);
		return fieldMap;
	}
	
	@Override
	public void insertData(Map<String, Object> valueMap) {
		super.insertData(valueMap);
		for (Entry<String, Object> entry : valueMap.entrySet()) {
			Object value = entry.getValue();
			
			//Dk rong
			if(entry.getValue() == null) continue;
			
			switch (entry.getKey()) {
			case "ageRestriction":
				this.ageRestriction = (int) value;
				break;
			case "size":
				this.size = (String) value;
				break;
			case "material":
				this.material = (String) value;
				break;
			
			default:
				break;
			}
		}
	}
}